#
# Cookbook Name:: om
# Recipe:: install
#
# Copyright 2013, IBM
#
# All rights reserved - Do Not Redistribute
#


wasuser = node[:was][:user]
wasgroup = node[:was][:group]
wasuserpw = node[:was][:userpw]
cuser = node[:chef][:user]
cgroup = node[:chef][:group]
deployment = node[:deployment]

inst_temp = node[:common][:inst_temp]+"/om/"

startinstr "Download OM setup"

#include_recipe "common::setup_wasuser"

directory "#{inst_temp}" do
  user cuser
  action :create
end
directory "#{inst_temp}/setup" do
  user cuser
  action :create
end
directory "#{inst_temp}/setup/thirdpartyjars" do
  user cuser
  action :create
end
directory "#{inst_temp}/setup/dbdriver" do
  user cuser
  action :create
end

id=0
[ node['om']['smcfs_path'], 
  node['om']['isccs_path']].each do |file|
  id=id+1
  bash "Fetch OM file: #{file}" do
   	user cuser
  	cwd inst_temp
  	creates "/tmp/fetch-om-file-#{id}.done"
  	code <<-EOH
  		scp -r #{node[:common][:scp_repo]}/#{file} #{inst_temp}/setup/ && touch "/tmp/fetch-om-file-#{id}.done"
  	EOH
  end
end

id=0
[  node['om']['tp_dhbcore'],
   node['om']['tp_jms'],
   node['om']['tp_providerutil'],
   node['om']['tp_mqjms'],
   node['om']['tp_jmqi'],
   node['om']['tp_mqheaders'],
   node['om']['tp_jta'],
   node['om']['tp_jndi'],
   node['om']['tp_fscontext'],
   node['om']['tp_connector'],
   node['om']['tp_ibmmq'],
   node['om']['tp_ant_contrib'],
   node['om']['tp_thinclient'],
   node['om']['tp_thinjms'],
   node['om']['tp_wccm'],
   node['om']['tp_crypto']].each do |file|
  id = id + 1
  bash "Fetch third-party file: #{file}" do
    user cuser
    cwd inst_temp
    creates "/tmp/fetch-3p-file-#{id}.done"
    code <<-EOH
      scp -r #{node[:common][:scp_repo]}/#{file} #{inst_temp}/setup/thirdpartyjars/ && touch "/tmp/fetch-3p-file-#{id}.done"
    EOH
  end
end

id=0
[  node['om']['dbdriver'],
   node['om']['dbdriver_lic']].each do |file|
  id = id + 1
  bash "Fetch db-driver file: #{file}" do
    user cuser
    cwd inst_temp
    creates "/tmp/fetch-dd-file-#{id}.done"
    code <<-EOH
      scp -r #{node[:common][:scp_repo]}/#{file} #{inst_temp}/setup/dbdriver/ && touch "/tmp/fetch-dd-file-#{id}.done"
    EOH
  end
end
bash "Change owner of OM files" do
	user "root"
	cwd inst_temp
	code <<-EOH
		chown -R #{node[:was][:user]}:#{node[:was][:group]} #{inst_temp}/setup
	EOH
end

stopinstr "Download OM setup"
